package cn.wolfcode.car.business.web.controller;

import cn.wolfcode.car.business.domain.BusinessStatement;
import cn.wolfcode.car.business.query.BusinessStatementQuery;
import cn.wolfcode.car.business.service.IBusinessStatementService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/business/statement")
public class BusinessStatementController {

    private String prefix="/business/statement";
    @Autowired
    private IBusinessStatementService businessStatementService;

    @RequestMapping("/listPage")
    public String toList(){
        return prefix+"/list";
    }
    @RequestMapping("/addPage")
    public String toadd(){
        return prefix+"/add";
    }
    @RequestMapping("/editPage")
    public String toedit(Long id, Model model){
        BusinessStatement statement = businessStatementService.get(id);
        model.addAttribute("statement",statement);
        return prefix+"/edit";
    }

    //分页+过滤
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<BusinessStatement> list(BusinessStatementQuery qo){
        return businessStatementService.query(qo);
    }
    //添加:结算单
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(BusinessStatement businessStatement){
        //在添加时，需要给定默认属性,这时我们只需要在实体类中给默认属性
        businessStatementService.save(businessStatement);
        return new AjaxResult().success("结算单添加成功！");
    }
    //修改：结算单
    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(BusinessStatement businessStatement){
        businessStatementService.update(businessStatement);
        return new AjaxResult().success("结算单修改成功！");
    }
    //删除结算单
    //如果是硬删除则还需要删除关联的结算单明细
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id){
        businessStatementService.deleteStatement(id);
        return new AjaxResult().success("删除成功！");
    }


}
